load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_test")
load("@rules_cc//cc:defs.bzl", "cc_binary")

cc_binary(
    name = "protoc-gen-grpc-web",
    srcs = [
        "grpc_generator.cc",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@com_google_protobuf//:protoc_lib",
    ],
)

# Runtime for `import_style=closure` and `mode={grpcweb,grpcwebtext}`
closure_js_library(
    name = "closure_grpcweb_runtime",
    visibility = ["//visibility:public"],
    exports = [
        ":abstractclientbase",
        ":clientreadablestream",
        ":error",
        ":grpcwebclientbase",
    ],
)

closure_js_library(
    name = "abstractclientbase",
    srcs = [
        "abstractclientbase.js",
    ],
    suppress = [
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":clientreadablestream",
        ":error",
        ":methodtype",
        ":requester",
    ],
)

closure_js_library(
    name = "calloptions",
    srcs = [
        "calloptions.js",
    ],
    suppress = [
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
)

closure_js_library(
    name = "clientoptions",
    srcs = [
        "clientoptions.js",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":interceptor",
    ],
)

closure_js_library(
    name = "clientreadablestream",
    srcs = [
        "clientreadablestream.js",
    ],
    visibility = ["//visibility:public"],
)

closure_js_library(
    name = "clientunarycallimpl",
    srcs = [
        "clientunarycallimpl.js",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":clientreadablestream",
    ],
)

closure_js_library(
    name = "error",
    srcs = [
        "error.js",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":metadata",
    ],
)

closure_js_library(
    name = "generictransportinterface",
    srcs = [
        "generictransportinterface.js",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@io_bazel_rules_closure//closure/library/net:xhrio",
        "@io_bazel_rules_closure//closure/library/net/streams:nodereadablestream",
    ],
)

closure_js_library(
    name = "grpcwebclientbase",
    srcs = [
        "grpcwebclientbase.js",
    ],
    suppress = [
        "checkTypes",
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":abstractclientbase",
        ":clientoptions",
        ":clientreadablestream",
        ":clientunarycallimpl",
        ":error",
        ":grpcwebclientreadablestream",
        ":interceptor",
        ":methodtype",
        ":requester",
        ":status",
        ":statuscode",
        "@io_bazel_rules_closure//closure/library/crypt:base64",
        "@io_bazel_rules_closure//closure/library/net:xhrio",
        "@io_bazel_rules_closure//closure/library/net/rpc:httpcors",
    ],
)

closure_js_library(
    name = "grpcwebclientreadablestream",
    srcs = [
        "grpcwebclientreadablestream.js",
    ],
    suppress = [
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":clientreadablestream",
        ":error",
        ":generictransportinterface",
        ":grpcwebstreamparser",
        ":status",
        ":statuscode",
        "@io_bazel_rules_closure//closure/library/crypt:base64",
        "@io_bazel_rules_closure//closure/library/events",
        "@io_bazel_rules_closure//closure/library/net:errorcode",
        "@io_bazel_rules_closure//closure/library/net:eventtype",
        "@io_bazel_rules_closure//closure/library/net:xhrio",
        "@io_bazel_rules_closure//closure/library/net:xmlhttp",
        "@io_bazel_rules_closure//closure/library/string",
    ],
)

closure_js_library(
    name = "grpcwebstreamparser",
    srcs = [
        "grpcwebstreamparser.js",
    ],
    suppress = [
        "checkTypes",
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@io_bazel_rules_closure//closure/library/asserts",
        "@io_bazel_rules_closure//closure/library/net/streams:streamparser",
    ],
)

closure_js_library(
    name = "interceptor",
    srcs = [
        "interceptor.js",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":clientreadablestream",
        ":requester",
    ],
)

closure_js_library(
    name = "metadata",
    srcs = [
        "metadata.js",
    ],
    visibility = ["//visibility:public"],
)

closure_js_library(
    name = "methodtype",
    srcs = [
        "methodtype.js",
    ],
    visibility = ["//visibility:public"],
)

closure_js_library(
    name = "requester",
    srcs = [
        "methoddescriptor.js",
        "methoddescriptorinterface.js",
        "request.js",
        "requestinternal.js",
        "unaryresponse.js",
        "unaryresponseinternal.js",
    ],
    suppress = [
        "reportUnknownTypes",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":calloptions",
        ":metadata",
        ":methodtype",
    ],
)

closure_js_library(
    name = "status",
    srcs = [
        "status.js",
    ],
    visibility = ["//visibility:public"],
)

closure_js_library(
    name = "statuscode",
    srcs = [
        "statuscode.js",
    ],
    visibility = ["//visibility:public"],
)

closure_js_test(
    name = "grpcwebclientbase_test",
    srcs = [
        "grpcwebclientbase_test.js",
    ],
    entry_points = [
        "goog:grpc.web.GrpcWebClientBaseTest",
    ],
    suppress = [
        "visibility",
        "checkTypes",
        "deprecated",
        "reportUnknownTypes",
        "strictCheckTypes",
    ],
    deps = [
        ":clientreadablestream",
        ":grpcwebclientbase",
        ":interceptor",
        "@io_bazel_rules_closure//closure/library/crypt:base64",
        "@io_bazel_rules_closure//closure/library/events",
        "@io_bazel_rules_closure//closure/library/net:eventtype",
        "@io_bazel_rules_closure//closure/library/structs:map",
        "@io_bazel_rules_closure//closure/library/testing:jsunit",
        "@io_bazel_rules_closure//closure/library/testing:testsuite",
    ],
)

closure_js_test(
    name = "grpcwebstreamparser_test",
    srcs = [
        "grpcwebstreamparser_test.js",
    ],
    entry_points = [
        "goog:grpc.web.GrpcWebStreamParserTest",
    ],
    suppress = [
        "reportUnknownTypes",
    ],
    deps = [
        ":grpcwebstreamparser",
        "@io_bazel_rules_closure//closure/library/testing:jsunit",
        "@io_bazel_rules_closure//closure/library/testing:testsuite",
    ],
)
